package test.test02.MyThread;

public class MyInterrupt02 {
    private static class MyRunnable implements Runnable{
        @Override
        public void run(){
            System.out.println("线程开始");
            while(!Thread.interrupted()){
                System.out.println("线程中断");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    // 重新设置中断状态
                    //Thread.currentThread().interrupt();
                    break;//中断标志位会被清除
                }
            }
            System.out.println("线程中断结束");
        }
    }
    public static void main(String[] args) throws InterruptedException {
        MyRunnable r1 = new MyRunnable();
        Thread t1 = new Thread(r1);
        t1.start();
        Thread.sleep(10*1000);
        t1.interrupt();
    }
}
